package be.javadevjunior.streeeloi.demineur.v1.business.generated.sound;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;


import be.javadevjunior.streeeloi.demineur.v1.business.TypeSound;
import be.javadevjunior.streeeloi.demineur.v1.business.beans.SoundBean;
import be.javadevjunior.streeeloi.demineur.v1.interfaces.ISoundManager;

public class SoundManager implements ISoundManager{
	private HashMap<String, SoundBean> sounds = new HashMap<>();

	@Override
	public void putSound(SoundBean sound) {
		if (sound!=null)
		sounds.put(sound.getNom(), sound);
		
	}

	@Override
	public SoundBean getSound(String name) {
		if (name==null) throw new NullPointerException();
		return sounds.get(name) ;
	}

	@Override
	public SoundBean[] getSoundByType(TypeSound type) {
		List<SoundBean> listtmp = new ArrayList<>();
		
		
		Set<String> cles = sounds.keySet();
		java.util.Iterator<String> it = cles.iterator();
		while (it.hasNext()){
		   String cle = (String) it.next(); 
		   SoundBean valeur = (SoundBean) sounds.get(cle); 
		   
		   if (valeur.getType().equals(type)) listtmp.add(valeur);
		}
		
		return listtmp.toArray(new SoundBean[0]);
		
		
		
		
		
	}

	

}
